<template>
  <div class="app">
    <van-divider :style="{ color: '#1989fa', borderColor: '#1989fa', padding: '0 16px' }">
      欢迎注册
    </van-divider>
    <van-form @submit="onSubmit">
      <van-field
        v-model="phone"
        name="手机号"
        label="手机号"
        placeholder="请输入手机号"
        :rules="[
          { required: true, message: '请填写手机号' },
          { pattern: /^1[3456789]\d{9}$/, message: '手机号格式有误' },
        ]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit">注册</van-button>
        <van-button round block type="info" @click.stop="login()" class="login"
          >去登陆</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from "mint-ui";
import url from "../tools/url";
export default {
  name: "Register",
  data() {
    return {
      phone: "",
      password: "",
    };
  },
  methods: {
    onSubmit() {
      var str = `phone=${this.phone}&password=${this.password}`;
      console.log(url.REGISTER);
      this.axios.post(url.REGISTER, str).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          Toast(res.data.message);
          this.$router.push("/Login");
        } else {
          Toast(res.data.message);
        }
      });
    },
    login() {
      this.$router.push("/Login");
    },
  },
};
</script>

<style scope>
.app {
  margin-top: 45px;
}
.btn {
  margin-top: 5px;
}
.login {
  margin-top: 10px;
}
</style>
